﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProductForm.ascx.cs"
    Inherits="SalesManagement.Controls.List.ProductForm" %>
<%@ Register Src="~/Controls/List/MeasureForm.ascx" TagName="WindowEditorMeasure"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/List/ProductPriceForm.ascx" TagName="WindowEditorPrice"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/List/CategoryForm.ascx" TagName="WindowEditorCategory"
    TagPrefix="uc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Hidden runat="server" ID="txtProductId" Text="">
</ext:Hidden>
<ext:Store ID="storeCategory" runat="server" RemoteSort="true">
    <Reader>
        <ext:JsonReader IDProperty="CategoryId">
            <Fields>
                <ext:RecordField Name="CategoryId" />
                <ext:RecordField Name="CategoryName" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<ext:Store ID="storeUnit" runat="server" RemoteSort="true">
    <Reader>
        <ext:JsonReader IDProperty="UnitId">
            <Fields>
                <ext:RecordField Name="UnitId" />
                <ext:RecordField Name="UnitName" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<ext:Store ID="storeObject" runat="server" RemoteSort="true">
    <Reader>
        <ext:JsonReader IDProperty="ObjectId">
            <Fields>
                <ext:RecordField Name="ObjectId" />
                <ext:RecordField Name="ObjectName" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<ext:Store ID="storeWarehouse" runat="server" RemoteSort="true">
    <Reader>
        <ext:JsonReader IDProperty="WarehouseId">
            <Fields>
                <ext:RecordField Name="WarehouseId" />
                <ext:RecordField Name="WarehouseName" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<ext:Window ID="winDetails" runat="server" Title="Hàng hóa" Icon="Package" Width="750"
    Height="450" Modal="true" Hidden="true" Layout="FormLayout" Resizable="false">
    <Items>
        <ext:TabPanel ID="tabProductForm" runat="server" ActiveTabIndex="0" BodyStyle="background-color:transparent;"
            BodyBorder="false" Border="true" MonitorValid="true">
            <Items>
                <ext:FormPanel ID="PanelWindow" Title="Thông tin hàng hóa" runat="server" Height="360"
                    Padding="5" Border="false" Frame="false" Layout="ColumnLayout" BodyStyle="background-color:transparent;"
                    BodyBorder="false" MonitorValid="true">
                    <Defaults>
                        <ext:Parameter Name="Anchor" Value="99%">
                        </ext:Parameter>
                    </Defaults>
                    <Items>
                        <ext:Panel ID="Panel1" runat="server" ColumnWidth="0.5" Layout="FormLayout" LabelWidth="120"
                            BodyStyle="background-color:transparent;" BodyBorder="false">
                            <Defaults>
                                <ext:Parameter Name="Anchor" Value="99%">
                                </ext:Parameter>
                            </Defaults>
                            <Items>
                                <ext:FieldSet ID="FieldSet1" runat="server" Title="Hàng hóa" Layout="FormLayout">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="99%">
                                        </ext:Parameter>
                                    </Defaults>
                                    <Items>
                                        <ext:TextField runat="server" ID="txtProductCode" FieldLabel="Mã hàng" AnchorHorizontal="70%"
                                            AllowBlank="false" BlankText="Không được bỏ trống">
                                        </ext:TextField>
                                        <ext:TextField runat="server" ID="txtProductName" FieldLabel="Tên hàng" AllowBlank="false" BlankText="Không được bỏ trống">
                                        </ext:TextField>
                                        <ext:CompositeField runat="server" FieldLabel="Nhóm hàng">
                                            <Defaults>
                                                <ext:Parameter Name="Anchor" Value="100%">
                                                </ext:Parameter>
                                            </Defaults>
                                            <Items>
                                                <ext:ComboBox ID="cboCategoryId" runat="server" Editable="false" DataIndex="Title"
                                                    StoreID="storeCategory" DisplayField="CategoryName" ValueField="CategoryId" />
                                                <ext:Button ID="btnAddCategory" runat="server" Icon="Add" Width="30">
                                                    <DirectEvents>
                                                        <Click OnEvent="btnAddCategory_Click" />
                                                    </DirectEvents>
                                                </ext:Button>
                                            </Items>
                                        </ext:CompositeField>
                                        <ext:CheckboxGroup ID="ckGroup" runat="server" Width="50">
                                            <Items>
                                                <ext:Checkbox ID="chkIsMaterial" runat="server" BoxLabel="Nguyên liệu" />
                                                <ext:Checkbox ID="chkIsProduct" runat="server" BoxLabel="Thành phẩm" />
                                            </Items>
                                        </ext:CheckboxGroup>
                                        <ext:CheckboxGroup ID="CheckboxGroup1" runat="server">
                                            <Items>
                                                <ext:Checkbox ID="chkIsRegular" runat="server" BoxLabel="Thường xuyên" />
                                                <ext:Checkbox ID="chkIsWarranty" runat="server" BoxLabel="Bảo hành" />
                                            </Items>
                                        </ext:CheckboxGroup>
                                        <ext:TextArea runat="server" ID="txtDescription" FieldLabel="Diễn giải" Height="50">
                                        </ext:TextArea>
                                    </Items>
                                </ext:FieldSet>
                                <ext:FieldSet ID="FieldSet4" runat="server" Title="Mua - Bán" Layout="FormLayout">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="99%">
                                        </ext:Parameter>
                                    </Defaults>
                                    <Items>
                                        <ext:ComboBox ID="cboOutUnit" runat="server" FieldLabel="Đơn vị xuất" Editable="false"
                                            StoreID="storeUnit" DisplayField="UnitName" ValueField="UnitId" />
                                        <ext:ComboBox ID="cboInputUnit" runat="server" FieldLabel="Đơn vị nhập" Editable="false"
                                            StoreID="storeUnit" DisplayField="UnitName" ValueField="UnitId" />
                                        <ext:NumberField runat="server" ID="txtInputPrice" FieldLabel="Giá mua" MaxLength="12"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                        <ext:NumberField runat="server" ID="txtOutputPrice" FieldLabel="Giá bán" MaxLength="12"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                    </Items>
                                </ext:FieldSet>
                            </Items>
                        </ext:Panel>
                        <ext:Panel ID="Panel2" runat="server" ColumnWidth="0.5" Layout="FormLayout" LabelWidth="120"
                            BodyStyle="background-color:transparent;" BodyBorder="false">
                            <Defaults>
                                <ext:Parameter Name="Anchor" Value="99%">
                                </ext:Parameter>
                            </Defaults>
                            <Items>
                                <ext:FieldSet ID="FieldSet3" runat="server" Title="Kho hàng" Layout="FormLayout">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="99%">
                                        </ext:Parameter>
                                    </Defaults>
                                    <Items>
                                        <ext:NumberField runat="server" ID="txtMinStock" FieldLabel="SL tồn tối thiểu" MaxLength="10"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField >
                                        <ext:NumberField runat="server" ID="txtMaxStock" FieldLabel="SL tồn tối đa" MaxLength="10"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                        <ext:ComboBox ID="cboWareHouse" runat="server" FieldLabel="Kho hàng" Editable="false"
                                            StoreID="storeWarehouse" DisplayField="WarehouseName" ValueField="WarehouseId" />
                                        <ext:ComboBox ID="cboStockUnit" runat="server" FieldLabel="Đơn vị lưu kho" Editable="false"
                                            StoreID="storeUnit" DisplayField="UnitName" ValueField="UnitId" />
                                    </Items>
                                </ext:FieldSet>
                                <ext:FieldSet ID="FieldSet2" runat="server" Title="Thuế - Chiết khấu" Layout="FormLayout"
                                    LabelWidth="120" Height="165">
                                    <Defaults>
                                        <ext:Parameter Name="Anchor" Value="99%">
                                        </ext:Parameter>
                                    </Defaults>
                                    <Items>
                                        <ext:NumberField runat="server" ID="txtInputVAT" FieldLabel="Thuế nhập" MaxLength="3"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                        <ext:NumberField runat="server" ID="txtInputDiscount" FieldLabel="Chiết khấu nhập"
                                            MaxLength="3" AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                        <ext:NumberField runat="server" ID="txtOutputVAT" FieldLabel="Thuế xuất" MaxLength="3"
                                            AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                        <ext:NumberField runat="server" ID="txtOutputDiscount" FieldLabel="Chiết khấu xuất"
                                            MaxLength="3" AllowBlank="false" BlankText="Không được bỏ trống" Text="0">
                                        </ext:NumberField>
                                    </Items>
                                </ext:FieldSet>
                            </Items>
                        </ext:Panel>
                    </Items>
                    <Listeners>
                        <ClientValidation Handler="#{btnSave}.setDisabled(!valid);" />
                    </Listeners>
                </ext:FormPanel>
                <ext:FormPanel ID="FormChangeUnit" Title="Đơn vị quy đổi" runat="server" Layout="RowLayout"
                    Border="false" Height="380" BodyStyle="background-color:transparent;" BodyBorder="false"
                    Disabled="true">
                    <Items>
                        <ext:Toolbar ID="tbMain" runat="server">
                            <Items>
                                <ext:ToolbarSpacer />
                                <ext:Button ID="btnAdd" runat="server" Text="Thêm" Icon="TableAdd">
                                    <DirectEvents>
                                        <Click OnEvent="btnAddUnit_Click" />
                                    </DirectEvents>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                        <ext:GridPanel ID="grdMeasure" runat="server" AutoExpandColumn="Ratio" RowHeight="1"
                            Layout="FitLayout" BodyStyle="background-color:transparent;" BodyBorder="false"
                            TrackMouseOver="true">
                            <Store>
                                <ext:Store ID="storeMeasure" runat="server" RemoteSort="true">
                                    <Reader>
                                        <ext:JsonReader>
                                            <Fields>
                                                <ext:RecordField Name="ProductId" />
                                                <ext:RecordField Name="Ratio" />
                                                <ext:RecordField Name="BasicUnit" />
                                                <ext:RecordField Name="RatioUnit" />
                                                <ext:RecordField Name="BasicName" />
                                                <ext:RecordField Name="RatioName" />
                                                <ext:RecordField Name="ProductName" />
                                                <ext:RecordField Name="IsActive" />
                                                <ext:RecordField Name="CreatedDate" />
                                                <ext:RecordField Name="CreatedBy" />
                                                <ext:RecordField Name="UpdatedDate" />
                                                <ext:RecordField Name="UpdatedBy" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <ColumnModel ID="ColumnModel1" runat="server">
                                <Columns>
                                    <ext:RowNumbererColumn />
                                    <ext:Column ColumnID="ProductName" DataIndex="ProductName" Header="Tên hàng" />
                                    <ext:Column ColumnID="BasicName" DataIndex="BasicName" Header="Đơn vị gốc" />
                                    <ext:Column ColumnID="RatioName" DataIndex="RatioName" Header="Đơn vị qui đổi" />
                                    <ext:Column ColumnID="Ratio" DataIndex="Ratio" Header="Tỷ lệ" />
                                    <ext:CommandColumn Width="80" Align="Center">
                                        <Commands>
                                            <ext:GridCommand Icon="NoteEdit" CommandName="Edit" Text="Cập nhật">
                                            </ext:GridCommand>
                                        </Commands>
                                    </ext:CommandColumn>
                                    <ext:CommandColumn Width="60" ButtonAlign="Center">
                                        <Commands>
                                            <ext:GridCommand Icon="NoteDelete" CommandName="Delete" Text="Xóa">
                                            </ext:GridCommand>
                                        </Commands>
                                    </ext:CommandColumn>
                                </Columns>
                            </ColumnModel>
                            <DirectEvents>
                                <Command OnEvent="grdMeasure_OnCommand">
                                    <ExtraParams>
                                        <ext:Parameter Name="command" Value="command" Mode="Raw" />
                                        <ext:Parameter Name="ProductId" Value="record.data.ProductId" Mode="Raw" />
                                        <ext:Parameter Name="BasicUnit" Value="record.data.BasicUnit" Mode="Raw" />
                                        <ext:Parameter Name="RatioUnit" Value="record.data.RatioUnit" Mode="Raw" />
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true" Message="Bạn có thật sự muốn xóa dòng dữ liệu này không?"
                                        Title="Thông báo" BeforeConfirm="if (command=='Edit') return false;" />
                                </Command>
                            </DirectEvents>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                            </SelectionModel>
                            <LoadMask ShowMask="true" />
                        </ext:GridPanel>
                    </Items>
                </ext:FormPanel>
                <ext:FormPanel ID="FormProductPrice" Title="Giá bán" runat="server" Height="360"
                    Border="false" Frame="false" Layout="RowLayout" BodyStyle="background-color:transparent;"
                    BodyBorder="false" Disabled="false">
                    <Items>
                        <ext:Toolbar ID="Toolbar1" runat="server">
                            <Items>
                                <ext:ToolbarSpacer />
                                <ext:Button ID="Button1" runat="server" Text="Thêm" Icon="MoneyAdd">
                                    <DirectEvents>
                                        <Click OnEvent="btnAddPrice_Click" />
                                    </DirectEvents>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                        <ext:GridPanel ID="grdPrice" runat="server" AutoExpandColumn="Price" RowHeight="1"
                            Layout="FitLayout" BodyStyle="background-color:transparent;" BodyBorder="false"
                            TrackMouseOver="true">
                            <Store>
                                <ext:Store ID="storeProductPrice" runat="server" RemoteSort="true">
                                    <Reader>
                                        <ext:JsonReader IDProperty="ProductPriceId">
                                            <Fields>
                                                <ext:RecordField Name="ProductPriceId" />
                                                <ext:RecordField Name="ProductId" />
                                                <ext:RecordField Name="Price" />
                                                <ext:RecordField Name="ProductName" />
                                                <ext:RecordField Name="ApplyDate" Type="Date" />
                                                <ext:RecordField Name="CreatedDate" />
                                                <ext:RecordField Name="CreatedBy" />
                                                <ext:RecordField Name="UpdatedDate" />
                                                <ext:RecordField Name="UpdatedBy" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <ColumnModel ID="ColumnModel2" runat="server">
                                <Columns>
                                    <ext:Column ColumnID="ProductName" DataIndex="ProductName" Header="Tên hàng" />
                                    <ext:DateColumn ColumnID="ApplyDate" DataIndex="ApplyDate" Header="Ngày áp dụng"
                                        Format="dd/MM/yyyy" />
                                    <ext:Column ColumnID="Price" DataIndex="Price" Header="Giá" />
                                    <ext:CommandColumn Width="80" Align="Center">
                                        <Commands>
                                            <ext:GridCommand Icon="NoteEdit" CommandName="Edit" Text="Cập nhật">
                                            </ext:GridCommand>
                                        </Commands>
                                    </ext:CommandColumn>                                   
                                </Columns>
                            </ColumnModel>
                            <DirectEvents>
                                <Command OnEvent="grdPrice_OnCommand">
                                    <ExtraParams>
                                        <ext:Parameter Name="command" Value="command" Mode="Raw" />
                                        <ext:Parameter Name="ProductPriceId" Value="record.data.ProductPriceId" Mode="Raw" />
                                        <ext:Parameter Name="ProductId" Value="record.data.ProductId" Mode="Raw" />
                                    </ExtraParams>                                    
                                </Command>
                            </DirectEvents>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" SingleSelect="true" />
                            </SelectionModel>
                            <LoadMask ShowMask="true" />
                        </ext:GridPanel>
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:TabPanel>
    </Items>
    <Buttons>
        <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
            <DirectEvents>
                <Click OnEvent="btnSave_Click">
                    <EventMask ShowMask="true" Msg="Đang lưu..." MinDelay="1000" />
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="btnCancel" runat="server" Text="Thoát" Icon="Cancel">
            <Listeners>
                <Click Handler="#{winDetails}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
<uc:WindowEditorMeasure ID="WindowEditorMeasure" runat="server" />
<uc:WindowEditorPrice ID="WindowEditorPrice" runat="server" />
<uc:WindowEditorCategory ID="WindowEditorCategory" runat="server" />
